//
//  FiveViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/3/6.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class FiveViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "展开"
        // Do any additional setup after loading the view.
        
        self.onCreateUIForNavigation();
        self.onCreateUIForView();
    }
    
    //TODO:UI
    fileprivate func onCreateUIForNavigation() {
        let backItem = UIBarButtonItem(title: "返回", style: .done, target: self, action: #selector(onBackAction));
        self.navigationItem.leftBarButtonItem = backItem;
    }
    
    fileprivate func onCreateUIForView() {
        self.view.backgroundColor = .white;
        
        let titleArray = ["cell展开","header展开"];
        var itemTop = 120;
        for index in 0 ... titleArray.count-1 {
            
            itemTop += 80*index;
            
            let bt = UIButton(type: .custom);
            bt.frame = CGRect(x: Int((screenMainSize.width-180)/2), y: itemTop, width: 180, height: 40);
            bt.backgroundColor = .clear;
            bt.setTitle(titleArray[index], for: .normal);
            bt.setTitleColor(.lightGray, for: .normal);
            bt.layer.cornerRadius = 5;
            bt.layer.masksToBounds = true;
            bt.layer.borderColor = UIColor.lightGray.cgColor;
            bt.layer.borderWidth = 1;
            bt.tag = 420 + index;
            bt.addTarget(self, action: #selector(onClickAction(bt:)), for: .touchUpInside);
            self.view.addSubview(bt);
        }
    }

    //TODO:Actions
    @objc fileprivate func onBackAction() {
        self.navigationController?.dismiss(animated: true, completion: nil);
    }
    
    @objc fileprivate func onClickAction(bt:UIButton) {
        switch bt.tag-420 {
        case 0:
            let vc = FiveContentViewController();
            self.navigationController?.pushViewController(vc, animated: true);
        case 1:
            let vc = FiveHeadViewController();
            self.navigationController?.pushViewController(vc, animated: true);
        default:
            ""
        }
    }
}
